# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Rémy Oudompheng <remy@archlinux.org>

pkgname=biber
epoch=1
pkgver=2.19
pkgrel=2
pkgdesc='A Unicode-capable BibTeX replacement for biblatex users'
arch=(any)
license=(PerlArtistic GPL)
url='https://github.com/plk/biber'
depends=(perl-autovivification
         perl-business-isbn
         perl-business-ismn
         perl-business-issn
         perl-class-accessor
         perl-data-compare
         perl-data-dump
         perl-data-uniqid
         perl-datetime-calendar-julian
         perl-datetime-format-builder
         perl-file-slurper
         perl-io-string # required by Biber::Output::bblxml
         perl-ipc-run3
         perl-lingua-translit
         perl-list-allutils
         perl-log-log4perl
         perl-lwp-protocol-https
         perl-mozilla-ca
         perl-parse-recdescent
         perl-perlio-utf8-strict
         perl-regexp-common
         perl-sort-key
         perl-text-balanced
         perl-text-bibtex
         perl-text-csv
         perl-text-roman
         perl-unicode-linebreak
         perl-xml-libxml-simple
         perl-xml-libxslt
         perl-xml-writer)
# ExtUtils::LibBuilder and Config::AutoConf are not actual makedepends
makedepends=(perl-module-build perl-test-differences)
checkdepends=(perl-capture-tiny perl-file-which texlive-bibtexextra texlive-latexextra)
options=(!emptydirs)
# The sourceforge tarball is missing bblxml.pm
source=(https://github.com/plk/biber/archive/v$pkgver/$pkgname-$pkgver.tar.gz
        https://github.com/plk/biber/commit/5f4a39d7.patch
        test.tex
        test.bib)
sha512sums=('427edd042e25fd6b763d60ad5bd3ce6fb68f9d6b15dfe387edc8c8445022cb2a4ba0999d7890fc51798dd95cbe82f82f6fc40b58df5a502c9c9b8485806c56d5'
            '1909c1a088bee73b9576a11aeb449105d40719f1d6ed9f842f524db8a93b55b816b2daa6853718ead1c522997006696402e7cf184de6fc02b7d2cbff82184c3b'
            '06babeb4ec2fd76b8a339070eb208c3c8c16665a085e4674ef3b61b3816d4408ca636b925fabe467adc5c32bf8eeb23d357f7ef979ac0a1722dc7f91142ec541'
            '68a00e41f200b8e24a674538b6581b88f84daef38a765790c1781365329203f60f4461a56dfa092bf336cc00c8801df1ee85f60d86fd384a8c039f913bdeeb2d')

prepare() {
  cd $pkgname-$pkgver
  patch -p1 -i ../5f4a39d7.patch # Fix test

  mkdir -p test
  cp ../test.{tex,bib} test/
}

build() {
  cd $pkgname-$pkgver
  unset PERL5LIB PERL_MM_OPT PERL_MB_OPT PERL_LOCAL_LIB_ROOT
  perl Build.PL
  ./Build
}

check() {
  cd $pkgname-$pkgver
  # Test a sample file
  pushd test
  latex test
  PERL5LIB=../blib/lib ../bin/biber test
  latex test
  popd
  # Run test suite
  unset PERL5LIB PERL_MM_OPT PERL_MB_OPT PERL_LOCAL_LIB_ROOT
  LC_CTYPE=en_US.UTF-8 BIBER_DEV_TESTS=1 ./Build test
}

package() {
  cd $pkgname-$pkgver
  unset PERL5LIB PERL_MM_OPT PERL_MB_OPT PERL_LOCAL_LIB_ROOT
  ./Build install installdirs=vendor destdir="$pkgdir"
}
